package com.example.springboot.entity;


import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 通用响应结果类
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@ApiModel(description = "通用响应结果")
public class Result<T> {

    @ApiModelProperty(value = "状态码", example = "200", required = true)
    private Integer code;

    @ApiModelProperty(value = "响应信息", example = "操作成功", required = true)
    private String message;

    @ApiModelProperty(value = "响应数据")
    private T data;

    /**
     * 成功响应
     */
    public static <T> Result<T> success(T data) {
        return new Result<>(200, "操作成功", data);
    }

    /**
     * 失败响应
     */
    public static <T> Result<T> error(Integer code, String message) {
        return new Result<>(code, message, null);
    }
}